<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="shortcut icon" href="./favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="./static/css/font.css">
    <link rel="stylesheet" href="./static/css/weadmin.css">
    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.0.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>

</head>
<body class="login-bg">

<div class="login">
    <div class="message">用户注册</div>
    <div id="darkbannerwrap"></div>

    <form method="post">
        <input id="username" name="username" placeholder="邮箱"  type="text">
        <hr class="hr15">
        <input id="password" name="password" placeholder="密码"  type="password" >
        <hr class="hr15">
        <input id="loginBtn2" value="注册"  style="width:100%;" type="button" >
        <hr class="hr20" >
    </form>
</div>

<script type="text/javascript">
    $(function () {
        $("#loginBtn2").click(function () {
            var username = $("#username").val();//取值
            var password = $("#password").val();
            if (!username) {
                alert("用户名必填!");
                $("#username").focus();//获取焦点
                return;
            }
            if (!password) {
                alert("密码必填!");
                $("#password").focus();//获取焦点
                return;
            }
            var email = /^[A-Za-z0-9]+([_\.][A-Za-z0-9]+)*@([A-Za-z0-9\-]+\.)+[A-Za-z]{2,6}$/;
            if(!email.test(username)){
                alert("请输入正确的邮箱格式！");
                $("#username").focus();//获取焦点
                return;
            }
            //var param = "username="+username+"&password="+password;
            var param = {"username": username, "password": password};
            $.post("/userregister", param, function (result) {
                if (result) {
                    window.location.href = "login";
                } else {
                    alert("注册失败");
                }
            });
        });
    });
</script>
</body>
</html>